/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Converters;

import DAO.DisciplinaDao;
import bean.DisciplinasGS;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author fernando
 */
@FacesConverter(forClass = DisciplinasGS.class)
public class DisciplinaGSConverser implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if (value == null || value.isEmpty()) {
            return null;
        }
        return new DisciplinaDao().buscar((Integer.valueOf(value)));
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        DisciplinasGS d = (DisciplinasGS) value;
        System.out.println("O id da Disciplina no converter:" + d.getId());
        if (d == null || d.getId() <= 0) {
            return null;
        }
        return String.valueOf(d.getId());
    }
}
